package 剑指offer;

public class 最小数 {
    static int max = 0;
    static boolean flag = true;

    public static void swap(int[] number, int i, int j) {
        int tmp = number[i];
        number[i] = number[j];
        number[j] = tmp;
    }

    public static void perm(int[] str, int k, int len) {
        if (k == len - 1) {
            String tmp = "";
            for (int i = 0; i < len; i++) {
                tmp += str[i];


            }
            if (flag) {
                max = Integer.parseInt(tmp);
                flag = false;
            }
            if (Integer.parseInt(tmp) < max)
                max = Integer.parseInt(tmp);
        } else {
            for (int i = k; i < len; i++) {
                swap(str, k, i);
                perm(str, k + 1, len);
                swap(str, k, i);

            }

        }
    }

    public static String PrintMinNumber(int[] numbers) {
        perm(numbers, 0, numbers.length);
        String x = String.valueOf(max);
        return x;

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] numbers = {3, 32, 321};
        System.out.println(PrintMinNumber(numbers));

    }

}
